<template>
	<view class="container">
		<button @click="subscribeMessage">订阅支付完成提醒</button>
		<button @click="navigateToRecordPage">手动记录采购</button>
		<button @click="simulatePayment">模拟支付并记录</button>
		<button @click="scan()">scan</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				templateId: 'SMl5m5gqXLviNbQ_tB_NLYizwJz80sG880856d2lWzI' // 替换为您在微信公众平台上申请的订阅消息模板ID
			};
		},
		methods: {
			// 引导员工订阅消息
			subscribeMessage() {
				const templateId = this.templateId;
				// 调用微信小程序的订阅消息API
				uni.requestSubscribeMessage({
					tmplIds: [templateId],
					success: (res) => {

						if (res[templateId] === 'accept') {
							uni.showToast({
								title: '订阅成功'
							});
						} else {
							uni.showToast({
								title: '订阅失败，请手动记录'
							});
						}
					},
					fail: () => {
						uni.showToast({
							title: '订阅失败，请手动记录',
							icon: 'none'
						});
					}
				});
			},
			// 跳转到记录页面
			navigateToRecordPage() {
				uni.navigateTo({
					url: '/pages/record/record'
				});
			},
			// 模拟支付并记录（测试用）
			simulatePayment() {
				// 模拟一个支付流程，并自动跳转到记录页面
				uni.navigateTo({
					url: '/pages/record/record?order_no=TEST12345&amount=100&pay_time=2023-09-28'
				});
			},
			scan() {
				uni.scanCode({
					success: (res) => {
						uni.navigateTo({
							url: res.result
						});
						// window.open(res.result, '_blank');
						console.log('扫码成功，二维码内容:', res.result);

					},
					fail: (err) => {
						console.log('扫码失败:', err);
					},
				});
			}
		}
	};
</script>

<style scoped>
	.container {
		padding: 20px;
	}

	button {
		margin: 10px 0;
		width: 100%;
		padding: 10px;
		background-color: #1aad19;
		color: white;
		border: none;
	}
</style>